<template>
  <div class="login-container bank-login">
    <!-- 返回按钮 -->
    <button class="back-home-btn" @click="goToHome">
      <span class="btn-icon">←</span>
      返回首页
    </button>
    <div class="login-header">
      <h1 class="platform-title">农产品融销一体平台</h1>
      <h2 class="role-title">银行机构登录</h2>
      <p class="welcome-text">金融服务三农，助力乡村振兴</p>
    </div>

    <div class="login-form-container">
      <div class="form-header">
        <div class="avatar bank-avatar">
          <i class="icon">🏦</i>
        </div>
        <h3>银行登录</h3>
        <p class="role-description">机构账户直接登录</p>
      </div>

      <form @submit.prevent="handleLogin" class="login-form">

        <div class="form-group">
          <label for="bank-username">银行机构名称</label>
          <input
            id="bank-username"
            v-model="form.username"
            type="text"
            placeholder="请输入银行机构名称"
            required
          />
        </div>

        <div class="form-group">
          <label for="bank-password">登录密码</label>
          <input
            id="bank-password"
            v-model="form.password"
            type="password"
            placeholder="请输入登录密码"
            required
          />
        </div>

        <div class="form-options">
          <label class="remember-me">
            <input type="checkbox" v-model="rememberMe" />
            <span>记住登录状态</span>
          </label>
          <a href="#" class="forgot-password">忘记密码？</a>
        </div>

        <button type="submit" class="login-btn bank-btn">登录系统</button>

        <div class="contact-admin">
          <p>如需开通银行机构账户，请联系平台管理员</p>
          <a href="tel:400-123-4567">客服热线：400-123-4567</a>
        </div>
      </form>
    </div>

    <div class="login-footer">
      <p>© 2025 农产品融销一体平台 · 银行服务系统</p>
    </div>
  </div>
</template>

<script setup>
import { ElMessage } from 'element-plus'
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { bankLoginApi } from '@/api/bank/login'

const router = useRouter()

const rememberMe = ref(false)
const form = ref({
  username: '',
  password: '',
  role: 'ROLE_BANK'
})

function goToHome() {
  router.push('/')
}

//登录
const handleLogin = async() => {
    const result = await bankLoginApi(form.value);
    if(result.code==200){
    ElMessage.success("登录成功");
    localStorage.setItem('loginUser', JSON.stringify(result.data))
    router.push('/bank/index')
  }else{
    //提示信息
    ElMessage.error(result.message);
  }
}

defineOptions({
  name: 'BankLogin'
})
</script>

<style scoped>
/* 添加返回按钮样式 */
.back-home-btn {
  position: absolute;
  top: 20px;
  left: 20px;
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid #4caf50;
  color: #4caf50;
  padding: 10px 15px;
  border-radius: 25px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.3s ease;
  z-index: 1000;
}

.back-home-btn:hover {
  background: #4caf50;
  color: white;
  transform: translateX(-5px);
}

.btn-icon {
  font-size: 16px;
  font-weight: bold;
}
/* 公共登录样式 */
.login-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.login-header {
  text-align: center;
  margin-bottom: 30px;
}

.platform-title {
  font-size: 2.2rem;
  font-weight: 700;
  color: #2e7d32;
  margin-bottom: 10px;
}

.role-title {
  font-size: 1.8rem;
  font-weight: 600;
  color: #333;
  margin-bottom: 5px;
}

.welcome-text {
  font-size: 1.1rem;
  color: #666;
}

.login-form-container {
  background: white;
  padding: 40px;
  border-radius: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 420px;
}

.form-header {
  text-align: center;
  margin-bottom: 30px;
}

.avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  margin: 0 auto 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
}

.avatar .icon {
  font-size: 2.5rem;
}

.form-header h3 {
  font-size: 1.5rem;
  font-weight: 600;
  color: #333;
  margin-bottom: 5px;
}

.role-description {
  font-size: 0.9rem;
  color: #666;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #333;
}

.form-group input {
  width: 100%;
  padding: 12px 15px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.3s ease;
  box-sizing: border-box;
}

.form-group input:focus {
  outline: none;
  border-color: #4caf50;
}

.form-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
  font-size: 0.9rem;
}

.remember-me {
  display: flex;
  align-items: center;
  color: #666;
}

.remember-me input {
  margin-right: 5px;
}

.forgot-password {
  color: #4caf50;
  text-decoration: none;
}

.forgot-password:hover {
  text-decoration: underline;
}

.login-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.login-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.register-link {
  text-align: center;
  margin-top: 20px;
  color: #666;
}

.register-link a {
  color: #4caf50;
  text-decoration: none;
  font-weight: 500;
}

.register-link a:hover {
  text-decoration: underline;
}

.register-form {
  margin-top: 20px;
}

.register-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #666, #888);
  color: white;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.register-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.back-to-login {
  text-align: center;
  margin-top: 15px;
}

.back-to-login a {
  color: #666;
  text-decoration: none;
}

.back-to-login a:hover {
  text-decoration: underline;
}

.login-footer {
  text-align: center;
  margin-top: 30px;
  color: #666;
  font-size: 0.9rem;
}

/* 响应式设计 */
@media (max-width: 480px) {
  .login-form-container {
    padding: 30px 20px;
    margin: 0 10px;
  }
  
  .platform-title {
    font-size: 1.8rem;
  }
  
  .role-title {
    font-size: 1.5rem;
  }
}

.bank-login {
  background: linear-gradient(135deg, #f3e5f5 0%, #e1bee7 100%);
}

.bank-avatar {
  background: linear-gradient(135deg, #9c27b0, #ba68c8);
}

.bank-btn {
  background: linear-gradient(135deg, #9c27b0, #ab47bc);
}

.bank-btn:hover {
  background: linear-gradient(135deg, #8e24aa, #9c42ab);
}

.contact-admin {
  text-align: center;
  margin-top: 20px;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 8px;
  font-size: 14px;
}

.contact-admin a {
  color: #9c27b0;
  text-decoration: none;
}
</style>